<?php

class Application_Model_DbTable_Postulantes extends Zend_Db_Table_Abstract
{

    protected $_name = 'postulantes';

	public function getPostulantes() {
		$select  = $this->_db->select()
			->from($this->_name);

		$result = $this->getAdapter()->fetchAll($select);

		return $result;
	}

	public function countPostulantes() {
		$select  = $this->_db->select('')
			->from($this->_name, array('total' => 'COUNT(*)'));

		$result = $this->getAdapter()->fetchAll($select);

		return $result[0]['total'];
	}
	
	public function countRegistrosmensuales() {
		$select  = $this->_db->select()
            ->from($this->_name, array('mes' => ' MONTH(fecha_alta)'))
            ->where("YEAR(`fecha_alta`) = ?", date("Y"));

		$resultPendientes = $this->getAdapter()->fetchAll($select);

		$meses = array();

		for($i=1;$i<=12;$i++){
			$meses[$i] = 0;
		}
		// print_r($resultPendientes);
		foreach($resultPendientes as $res){
			$meses[$res['mes']]++;
		}
		// print_r($meses);die();
        //setloocale(LC_ALL, 'es_AR');
        //TODO: http://www.hashbangcode.com/blog/setting-locale-zend-framework-421.html
        $ms = array('Ene','Feb','Mar','Abr','May','Jun','Jul','Ago','Sep','Oct','Nov','Dic');
        $datos = array();
        foreach($meses as $numMes => $totalMensual){
            //$datos[date("F", mktime(0, 0, 0, $numMes, 10))] = $totalMensual;
            $datos[$ms[$numMes-1]] = $totalMensual;
        }
		//print_r($datos);die();

		return $datos;
	}
}

